﻿#include "../head/ue_tx_pusch_bit_gen.h"
#include "../head/Ue_Tx_FilePrintf.h"

///=================================================================================================
/// pusch_tx_bitgen_fix ==pusch_tx_bitgen.
///
/// @author guozhiyuan
/// @date   2018/4/03
///
/// @param [in]        SimParam            参数输入结构体.
/// @param [inout]     *BRP_PUSCH_Op       pusch tx bit pointer.
/// @par History
/// -
///       Date|       Author|        Version|        DESCRIPTION
/// ----------|-------------|---------------|-------------------
/// 2018-04-03|   Guozhiyuan|          0.0.1|            created
/// 2018-04-17|      Yangyan|          0.0.2|            封装和整理，添加DMRS和PUSCH共符号
/// 2018-05-30|  zhangyanqun|          0.0.1|            created 复制定点调用代码
/// 2018-07-23|      Yangyan|          0.0.4|            更新原始比特为sch csi1 csi2 ack比特串行输出,统一定浮点调用接口
/// 2018-07-24|      Yangyan|          0.0.5|            添加编码前传输块比特输出
/// 2018-09-08|      Yangyan|          0.0.6|            发csi2时，csi1中Rank的值添加打桩值
///=================================================================================================
void pusch_tx_bitgen(
    IN  stULParamTable       *SimParam,
    OUT int8    BRP_ULSCH_Op[][CW_MAX_LEN],
    OUT UINT8  PUSCH_CwBit[][CW_MAX_LEN], // sch csi1 csi2 ack; cc bit
    OUT int PUSCH_CwLen[][4], // sch csi1 csi2 ack; cc bitlen
    OUT UINT8  PUSCH_TbBit[][CW_MAX_LEN], // sch csi1 csi2 ack; payload bit
    OUT int PUSCH_TbLen[][4] // sch csi1 csi2 ack; payload bitlen
)
{
    /* 循环计数 */
    int m, iCw, Qm, NL, NLxQm;
    //sc input parameter
    stScParam *pstScParam;
    // ldpc
    stLDPCParamTable  *pstLDPCParamTable;
    pstScParam = (stScParam *)malloc(sizeof(stScParam));
    pstLDPCParamTable = (stLDPCParamTable *)malloc(sizeof(stLDPCParamTable));

    //
    UINT8    *BRP_ULHAQR_Op, *pACK_TbBit;
    UINT8    *BRP_ULCSI1_Op, *pCSI1_TbBit;
    UINT8    *BRP_ULSCHData_Op, *pSCH_TbBit;
    UINT8    scdata[12];

#if CC_READFLAG
    char filename[256];//for DT print
    FILE *fp_OriBit;
#endif
    //
    BRP_ULHAQR_Op = (UINT8 *)malloc(MAX_E_LENGTH * sizeof(UINT8));
    BRP_ULCSI1_Op = (UINT8 *)malloc(MAX_E_LENGTH * sizeof(UINT8));
    BRP_ULSCHData_Op = (UINT8 *)malloc(CW_MAX_LEN * sizeof(UINT8));
    pACK_TbBit = (UINT8 *)malloc(MAX_E_LENGTH * sizeof(UINT8));
    pCSI1_TbBit = (UINT8 *)malloc(MAX_E_LENGTH * sizeof(UINT8));
    pSCH_TbBit = (UINT8 *)malloc(CW_MAX_LEN * sizeof(UINT8));
    //=============================================================//
    srand(SimParam->iTTI * SimParam->iUe); // 为了能复现UCI的随机比特，每次重置rand的起点
	
    for (iCw = 0; iCw < SimParam->CwNum; iCw++)
    {
        //
        memset(BRP_ULHAQR_Op, 0, MAX_E_LENGTH * sizeof(UINT8));
        memset(BRP_ULCSI1_Op, 0, MAX_E_LENGTH * sizeof(UINT8));
        memset(BRP_ULSCHData_Op, 0, CW_MAX_LEN * sizeof(UINT8));
        memset(pACK_TbBit, 0, MAX_E_LENGTH * sizeof(UINT8));
        memset(pCSI1_TbBit, 0, MAX_E_LENGTH * sizeof(UINT8));
        memset(pSCH_TbBit, 0, CW_MAX_LEN * sizeof(UINT8));

		Qm = SimParam->ModuMod[iCw] > 0 ? (SimParam->ModuMod[iCw] * 2) : 1;

        NL = SimParam->LayerNumOf1cw[iCw];
        NLxQm = NL * Qm;
        if (SimParam->PUSCHMultiFlag == 1)
        {
            //CSI1
			if (SimParam->PUSCH_CSI1_Flag == 1)
			{
				for (m = 0; m < (int)SimParam->PUSCH_CSI1_A_Len; m++) // payload bitlen
				{
					pCSI1_TbBit[m] = (UINT8)(rand() % 2); // csi rand bit
				}

				memset(pstScParam, 0, sizeof(stScParam));
				pstScParam->WX_Flag = SimParam->WX_Flag; // WX_Flag
				pstScParam->uwTBSize = SimParam->PUSCH_CSI1_A_Len;   //TB Size 1~11, payload bitlen
				pstScParam->uwE = SimParam->PUSCH_CSI1_E_Len;
				pstScParam->ucModType = SimParam->ModuMod[iCw];  // Mod Type: 0,BPSK;1:QPSK;2:16QAM;3:64QAM;4:256QAM
#if CC_READFLAG
				// open fp_OriBit
				sprintf_s(filename, "csi1_sequence_in.am");
				//sprintf_s(filename, "UNISOC/testvector%d/csi1_sequence_in.am", CASEIDX_PRINT);
				fopen_s(&fp_OriBit, filename, "r");
				if (fp_OriBit == NULL)
				{
					printf("cannot open %s!\n", filename);
					throw(0);
				}

				// read from file
				for (m = 0; m < SimParam->PUSCH_CSI1_A_Len; m++)
				{
					fscanf_s(fp_OriBit, "%d", &pstPolarData->aucInfoCode[m]);
					pCSI1_TbBit[m] = pstPolarData->aucInfoCode[m];
					scdata[m] = pCSI1_TbBit[m];
				}
				fclose(fp_OriBit);
#else
				// Create input bits
				for (m = 0; m < (int)SimParam->PUSCH_CSI1_A_Len; m++)
				{
					scdata[m] = pCSI1_TbBit[m];
				}
#endif
				sc_cc_f(pstScParam, &scdata[0], BRP_ULCSI1_Op);
			}

            //ACK
            if (SimParam->PUSCH_HARQ_Flag == 1)
            {
                memset(pstScParam, 0, sizeof(stScParam));
				pstScParam->WX_Flag = SimParam->WX_Flag; // WX_Flag
                pstScParam->uwTBSize = SimParam->PUSCH_HARQ_A_Len;   //TB Size 1~11
                pstScParam->uwE = SimParam->PUSCH_HARQ_E_Len;
                pstScParam->ucModType = SimParam->ModuMod[iCw];  // Mod Type: 0,BPSK;1:QPSK;2:16QAM;3:64QAM;4:256QAM
#if CC_READFLAG
                // open fp_OriBit
                sprintf_s(filename, "harq_sequence_in.am");
                //sprintf_s(filename, "UNISOC/testvector%d/harq_sequence_in.am", CASEIDX_PRINT);
                fopen_s(&fp_OriBit, filename, "r");
                if (fp_OriBit == NULL)
                {
                    printf("cannot open %s!\n", filename);
                    throw(0);
                }

                // read from file
                for (m = 0; m < SimParam->PUSCH_HARQ_A_Len; m++)
                {
                    fscanf_s(fp_OriBit, "%d", &scdata[m]);
                    pACK_TbBit[m] = scdata[m];
                }
                fclose(fp_OriBit);
#else
                // Create input bits
                for (m = 0; m < (int)SimParam->PUSCH_HARQ_A_Len; m++)
                {
                    pACK_TbBit[m] = (UINT8)(rand() % 100 > 50 ? 1 : 0);
                    scdata[m] = pACK_TbBit[m];
                }
#endif
                sc_cc_f(pstScParam, &scdata[0], BRP_ULHAQR_Op);
            }
        }
        // SCH
        if ((SimParam->PUSCHData_BitLen[iCw] > 0) && (SimParam->PUSCH_SCH_Flag == 1))
        {
            memset(pstLDPCParamTable, 0, sizeof(stLDPCParamTable));

                pusch_cc_f(SimParam, iCw, pstLDPCParamTable, BRP_ULSCHData_Op, pSCH_TbBit);

			}    


		vFilePrintPUSCHmultiplexUCIStreamBit( SimParam,BRP_ULCSI1_Op,BRP_ULHAQR_Op,BRP_ULSCHData_Op);
		//打印PUSCh ack,csi1,csi2比特流，每行32bit,16进制

		// sch csi1 csi2 ack payload串行输出，与收端译码后bit分别比对统计TBber
		PUSCH_TbLen[iCw][0] = SimParam->PUSCH_SCH_Flag==1?pstLDPCParamTable->uwTBLen:0;
		PUSCH_TbLen[iCw][1] = SimParam->PUSCH_CSI1_Flag==1?SimParam->PUSCH_CSI1_A_Len:0;
		PUSCH_TbLen[iCw][2] = SimParam->PUSCH_HARQ_Flag==1?SimParam->PUSCH_HARQ_A_Len:0;
		memcpy(&PUSCH_TbBit[iCw][0], pSCH_TbBit, PUSCH_TbLen[iCw][0]*sizeof(UINT8));
		memcpy(&PUSCH_TbBit[iCw][0+PUSCH_TbLen[iCw][0]], pCSI1_TbBit, PUSCH_TbLen[iCw][1]*sizeof(UINT8));
		memcpy(&PUSCH_TbBit[iCw][0+PUSCH_TbLen[iCw][0]+PUSCH_TbLen[iCw][1]], pACK_TbBit, PUSCH_TbLen[iCw][2]*sizeof(UINT8));
		// sch csi1 csi2 ack cc bit串行输出，与收端解调后软bit分别比对统计rawber
		PUSCH_CwLen[iCw][0] = SimParam->PUSCH_SCH_Flag==1? pstLDPCParamTable->uwCwLen:0;
		PUSCH_CwLen[iCw][1] = SimParam->PUSCH_CSI1_Flag==1? SimParam->PUSCH_CSI1_E_Len:0;
		PUSCH_CwLen[iCw][2] = SimParam->PUSCH_HARQ_Flag==1?SimParam->PUSCH_HARQ_E_Len:0;
		memcpy(&PUSCH_CwBit[iCw][0], BRP_ULSCHData_Op, PUSCH_CwLen[iCw][0]*sizeof(UINT8));
		memcpy(&PUSCH_CwBit[iCw][0+PUSCH_CwLen[iCw][0]], BRP_ULCSI1_Op, PUSCH_CwLen[iCw][1]*sizeof(UINT8));
		memcpy(&PUSCH_CwBit[iCw][0+PUSCH_CwLen[iCw][0]+PUSCH_CwLen[iCw][1]], BRP_ULHAQR_Op, PUSCH_CwLen[iCw][2]*sizeof(UINT8));

		// multiplexing
		pusch_tx_multiplexing(SimParam,BRP_ULHAQR_Op,BRP_ULCSI1_Op,BRP_ULSCHData_Op,BRP_ULSCH_Op[iCw],iCw);

    }//end of iCw
    // free
	/////============参数打印===========================
	ue_tx_FPGA_PARM_print(SimParam,pstLDPCParamTable,1 ) ;//  给DSP打印参数
	ue_rx_PARM_print(SimParam,pstLDPCParamTable,1) ;// 链路参数打印

    free(pstScParam);
    free(pstLDPCParamTable);

    free(BRP_ULHAQR_Op);
    free(BRP_ULCSI1_Op);
    free(BRP_ULSCHData_Op);
    free(pACK_TbBit);
    free(pCSI1_TbBit);
    free(pSCH_TbBit);
    return;
}

///=================================================================================================
/// pusch_tx_multiplexing.
///
/// @author guozhiyuan
/// @date   2018/4/03
///
/// @param [in]    SimParam        参数输入结构体.
/// @param [in]    *BRP_ULHAQR_Op  HARQ data pointer.
/// @param [in]    *BRP_ULCSI1_Op  CSI1 data pointer.
/// @param [in]    *BRP_ULCSI2_Op  CSI2 data pointer.
/// @param [in]    *BRP_ULSCHData_Op  SCH Data data pointer.
/// @param [out]   *BRP_PUSCH_Op    multiplexing pusch data pointer.
/// @param [in]    iCw              code word idx.
/// @par History
/// -
///       Date|       Author|        Version|        DESCRIPTION
/// ----------|-------------|---------------|-------------------
/// 2018-04-03|   Guozhiyuan|          0.0.1|            created
/// 2018-04-17|      Yangyan|          0.0.2|            封装和整理，添加DMRS和PUSCH共符号
/// 2018-05-30|  zhangyanqun|          0.0.1|            created 复制定点调用代码
/// 2018-07-23|      Yangyan|          0.0.4|            更新原始比特为sch csi1 csi2 ack比特串行输出，统一定点浮点调用
/// 2018-07-24|      Yangyan|          0.0.5|            sch csi1 csi2 ack比特串行输出搬移至外部模块
///=================================================================================================
void pusch_tx_multiplexing(
    IN  stULParamTable *SimParam,
    IN  UINT8            *BRP_ULHAQR_Op, //harq
    IN  UINT8            *BRP_ULCSI1_Op, //csi1
    IN  UINT8            *BRP_ULSCHData_Op,//data
    OUT int8            BRP_ULSCH_Op[CW_MAX_LEN],//pusch
    IN  int              iCw
)
{

    //38.212 6.2.7
    int iSym, iRe, v, MaxScNum, NL, Qm, NLxQm, pusch_QAMSymIdx, d_ack;
    int counter_sch, counter_ack, counter_csi1, counter_csi2;
    uint8 counter_flag = 0;
    char   cFileAddr[256] = {0};
    MaxScNum = SimParam->PUSCH_RB_Num * SC_PER_RB;

	Qm = SimParam->ModuMod[iCw] > 0 ? (SimParam->ModuMod[iCw] * 2) : 1;

    NL = SimParam->LayerNumOf1cw[iCw];
    NLxQm = NL * Qm;
    //placing
    counter_sch = 0;
    counter_ack = 0;
    counter_csi1 = 0;
    counter_csi2 = 0;
    pusch_QAMSymIdx = 0;
    d_ack = 0 ;
    for (iSym = 0 ; iSym < MAXSYMNUM ; iSym++)
    {
        for (iRe = 0 ; iRe < MaxScNum; iRe++)
        {

            if (0 == SimParam->pusch_re_flag[iSym][iRe])// -2: CSI2 punctring by ACK, -1: Data punctring by ACK, 0: UL-SCH, 1: ACK, 2:CSI1, 3: CSI2, 4: DMRS, 5: NULL, 6: SRS, 7:PT-RS
            {
                for (v = 0 ; v < NLxQm ; v++)
                {
                    BRP_ULSCH_Op[pusch_QAMSymIdx * NLxQm + v]  = (int8)BRP_ULSCHData_Op[counter_sch];
                    counter_sch++;
                }
                pusch_QAMSymIdx++;
            }
            else if (1 == SimParam->pusch_re_flag[iSym][iRe]) //ACK
            {
                if (SimParam->PUSCH_HARQ_K_Len <= 2) //需要更新
                {
                    ;//ack覆盖csi2或者sch，目前参数计算暂不支持
                }
                else
                {
                    for (v = 0 ; v < NLxQm ; v++)
                    {
                        BRP_ULSCH_Op[pusch_QAMSymIdx * NLxQm  + v] = (int8)BRP_ULHAQR_Op[counter_ack];
                        counter_ack++;
                    }
                    pusch_QAMSymIdx++;
                }
            }
            else if (2 == SimParam->pusch_re_flag[iSym][iRe]) //CSI1
            {
                for (v = 0 ; v < NLxQm ; v++)
                {
                    BRP_ULSCH_Op[pusch_QAMSymIdx * NLxQm + v]  = (int8)BRP_ULCSI1_Op[counter_csi1];
                    counter_csi1++;
                }
                pusch_QAMSymIdx++;

            }
            else if (-1 == SimParam->pusch_re_flag[iSym][iRe]) //-1: ACK-ULSCH_PUNC
            {
                for (v = 0 ; v < NLxQm ; v++)
                {
                    BRP_ULSCH_Op[pusch_QAMSymIdx * NLxQm  + v] = (int8)BRP_ULHAQR_Op[counter_ack];
                    counter_ack++;
                    counter_sch++;
                }
                pusch_QAMSymIdx++;
            }
            else if (-2 == SimParam->pusch_re_flag[iSym][iRe]) // -2:ACK-CSI2_PUNC
            {
                for (v = 0 ; v < NLxQm ; v++)
                {
                    BRP_ULSCH_Op[pusch_QAMSymIdx * NLxQm  + v] = (int8)BRP_ULHAQR_Op[counter_ack];
                    counter_ack++;
                    counter_csi2++;
                }
                pusch_QAMSymIdx++;
            }
            else
            {
                ;//Other
            }
        }
    }
    // printf
    //sprintf_s(cFileAddr, "Result/PUSCHTestData/posteqData/intlv_map.am");
	sprintf_s(cFileAddr, "Result/PUSCHTestData/CASE%d/intlv_map.am", CASEIDX_PRINT);
    vFileprintf_intlv_map(cFileAddr, SimParam);

}
///=================================================================================================
/// vFileprintf_intlv_map
///
/// @author guozhiyuan
///================================================================================================
void vFileprintf_intlv_map(
    IN char cFileName[256],
    IN  stULParamTable *SimParam
)
{
    FILE  *Fp;
    char   cParaName[256] = {0};
    int     iRB, iSym, iRe;
    if (!ULTEST_PRINTFLAG)
    {
        return;
    }
    fopen_s(&Fp, cFileName, "a+");
    for (iRB = 0 ; iRB < SimParam->PUSCH_RB_Num; iRB++)
    {
        sprintf_s(cParaName, "intlv_map%d\t", iRB);
        fprintf(Fp, cParaName); // ACK RE pos in isymIdx symbol
        // for(iSym = 0; iSym < SimParam->PUSCH_SymNum ; iSym ++) // deleted by shanshan @20180910
        for (iSym = SimParam->PUSCH_Symb_Start ; iSym < SimParam->PUSCH_Symb_Start + SimParam->PUSCH_SymNum ; iSym ++)
        {
            for (iRe = 0; iRe < SC_PER_RB; iRe++)
            {
                fprintf(Fp, "%d", SimParam->pusch_re_flag[iSym][iRB * SC_PER_RB + iRe]); // -2: CSI2 punctring by ACK, -1: Data punctring by ACK, 0: UL-SCH, 1: ACK, 2:CSI1, 3: CSI2, 4: DMRS, 5: NULL, 6: SRS, 7:PT-RS
            }
            fprintf(Fp, "\t");// one symbol finish
        }
        fprintf(Fp, "\n");// one RB finish
    }
    fclose(Fp);
    return;
}
///=================================================================================================
/// vFileprintf_intlv_map
///
/// @author guozhiyuan
///================================================================================================
void vFileprintf_polar_para(
    IN char cFileName[256],
    IN  stULParamTable *SimParam
)
{
    FILE *Fp;
    char cParaName[32] = {0};
    int  iSym;
    if (!ULTEST_PRINTFLAG)
    {
        return;
    }
    else
    {
        fopen_s(&Fp, cFileName, "a+");
        for (iSym = 0 ; iSym < MAXSYMNUM ; iSym ++)
        {
            fprintf(Fp, "ack_symb%d_d       \t\t %d\n",  iSym, SimParam->ack_d[iSym]);
            fprintf(Fp, "ack_symb%d_restart \t\t %d\n",  iSym, SimParam->ack_restart[iSym]);
            fprintf(Fp, "csi1_symb%d_d      \t\t %d\n",  iSym, SimParam->csi1_d[iSym]);
            fprintf(Fp, "csi1_symb%d_restart\t\t %d\n", iSym, SimParam->csi1_restart[iSym]);
        }
        fclose(Fp);
        return;
    }

}
///=================================================================================================
/// vFileprintf_intlv_map
///
/// @author guozhiyuan
///================================================================================================
void vFileprintf_arm_polar_para(
    IN char cFileName[256],
    IN stULParamTable    *SimParam,
    IN stPolarParam *pstPolarParam,
    IN stPolarData  *pstPolarData)
{
    FILE *Fp;
    char cParaName[32] = {0};
    if (!ULTEST_PRINTFLAG)
    {
        return;
    }
    else
    {
        fopen_s(&Fp, cFileName, "a+");
        strcpy_s(cParaName, "ack_flag");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", SimParam->PUSCH_HARQ_Flag);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "csi1_flag");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", SimParam->PUSCH_CSI1_Flag);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "cch_flag");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", SimParam->PUSCH_SCH_Flag);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "polar_n");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->uwNLen);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "polar_k");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->uwKLen);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "crc_sel");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->ucULFlag + ((11 == pstPolarParam->ucCrcLen) ? 1 : 0));
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "itlv_flag");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->ucULFlag);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "ba_table");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        for (int i = 0; i < (int)pstPolarParam->uwNLen; i = i + 16)
        {
            for (int k = 16; k > 0; k = k - 2)
            {
                fprintf(Fp, "%01X", pstPolarData->BA_TABLE[i + k - 1] * 4 + pstPolarData->BA_TABLE[i + k - 2]);
            }
            fprintf(Fp, "\n");
        }
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "polar_ack_t");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->ucT);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "polar_csi1_t");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->ucT);
        fprintf(Fp, "\n");
        strcpy_s(cParaName, "polar_csi2_t");
        fprintf(Fp, "%-32.32s\t", cParaName); // ACK RE pos in isymIdx symbol
        fprintf(Fp, "%08X", pstPolarParam->ucT);
        fprintf(Fp, "\n");
        fclose(Fp);
        return;
    }

}
///=================================================================================================
/// vFileprintf_intlv_map
///
/// @author guozhiyuan
///================================================================================================
void vFileprintf_fpga_polar_para(
    IN char cFileName[256],
    IN  stULParamTable    *SimParam,
    IN stPolarParam *pstPolarParam,
    IN stPolarData  *pstPolarData)
{
    FILE *Fp;
    char cParaName[32] = {0};
    if (!ULTEST_PRINTFLAG)
    {
        return;
    }
    else
    {
        fopen_s(&Fp, cFileName, "a+");
        fprintf(Fp, "%08x //%s\n", SimParam->PUSCH_HARQ_Flag, "ack_flag"); // ack_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", SimParam->PUSCH_CSI1_Flag, "csi1_flag"); // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", SimParam->PUSCH_SCH_Flag, "cch_flag"); // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", pstPolarParam->uwNLen, "polar_n"); // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", pstPolarParam->uwKLen, "polar_k"); // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", (pstPolarParam->ucULFlag * (pstPolarParam->ucULFlag + ((pstPolarParam->uwKLen >= 30) ? 1 : 0))), "crc_sel"); // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", pstPolarParam->ucULFlag, "itlv_flag");   // sch_flag: 0 - exist, 1 - not exsit
        for (int i = 0; i < (int)pstPolarParam->uwNLen; i = i + 16)
        {
            for (int k = 16; k > 0; k = k - 2)
            {
                fprintf(Fp, "%01X", pstPolarData->BA_TABLE[i + k - 1] * 4 + pstPolarData->BA_TABLE[i + k - 2]);
            }
            fprintf(Fp, " //%s[%d:%d]\n", "ba_table", (i + 16) * 2 - 1, i * 2);
        }
        fprintf(Fp, "%08x //%s\n", pstPolarParam->ucT, "polar_ack_t");   // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", pstPolarParam->ucT, "polar_csi1_t");   // sch_flag: 0 - exist, 1 - not exsit
        fprintf(Fp, "%08x //%s\n", pstPolarParam->ucT, "polar_csi2_t");   // sch_flag: 0 - exist, 1 - not exsit
        fclose(Fp);
        return;
    }

}

